#ifndef MAIN
#define MIAN_

#include "Hashtable.h"
#include "Quicksort.h"
#include<cstring>
#include<string>
#include<iostream>
#include<stdio.h>
#include<vector>

#define Hashnumber 1024

int main(int argc, char *argv[])
{
  Hashtable table;
  FILE* fp;
  char buf[1024];
  char* p;
  std::vector<DATA> arr;
  int index = 0;
  fp = fopen("alibaba.txt", "r");
  if (fp == NULL)
    {
      std::cout << "Error!" << std::endl;
      exit(-1);
    }
  while(fgets(buf,sizeof(buf),fp))
    {
      buf[strlen(buf)-1] = '\0';
      if (strcmp("", buf) == 0)
	continue;
      p = strtok(buf, "'\n','\t','.',',' ',':','!','\"','?'" );
      while(p != NULL)
	{
	  table.insert(p);
	  p = strtok(NULL,"'\n','\t','.',',' ',':','!','\"','?'" );
	}
    }
  Hashnode* head = table.head;
  for(int i = 0; i < Hashnumber; i++)
    {
      if ((head+i)->isempty == true)
	continue;
      else
	{
	  for(Hashnode* q = (head + i);
	      q != q->nil ; q = q->get_next())
	    {
	      DATA A(index,q->get_count(),
		     q->get_word());
	      arr.push_back(A);
	      index++;
	    }
	}
    }
  for (int i = 0;i<20;i++)
    {
      DATA tmp = arr[i];
      std::cout << "word:" << tmp.get_word() << "  count:" << tmp.get_val() << std::endl;
    }
    fclose(fp);
    return 0;
};

#endif
